package gui;

import java.awt.BorderLayout;
import java.util.Date;

import javax.swing.JFrame;

import model.listener.UserListener;

public class MainWindow extends JFrame implements UserListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1688432998871253086L;
	private Logger logger = new Logger();
	private Statebar statebar = new Statebar();

	public MainWindow() {
		this.setLayout(new BorderLayout());
		this.add(logger,BorderLayout.CENTER);
		this.add(statebar,BorderLayout.SOUTH);
		this.setTitle("Logger");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.pack();
	}

	@Override
	public void lostUser(int userId, long time) {
		Date d = new Date(time);
		String text = "[" + d.toString() + "]User : " + userId + " leaves ";
		logger.addLine(text);
	}

	@Override
	public void newUser(int userId, long time) {
		Date d = new Date(time);
		String text = "[" + d.toString() + "]User : " + userId + " comes ";
		logger.addLine(text);
	}

	public void setState(String ref) {
		statebar.setText(ref);
	}
}
